﻿using Coolzon.Realtime.Contracts.CommandData;

namespace Coolzon.Realtime.ServerApp.ServiceImplement
{
    /// <summary>
    /// 请求数据工厂
    /// </summary>
    public class RequestHandlerFactory
    {
        /// <summary>
        /// 创建请求事件
        /// </summary>
        /// <param name="scenario">场景编码</param>
        /// <param name="command">指令编码</param>
        /// <returns></returns>
        public static IRequestHandler CreateHandler(byte scenario, byte command)
        {
            IRequestHandler handler = null;
            if (scenario == SCENARIO.CONNECT)
            {
                if (command == COMMAND.CONNECT.UPLOADVIEWSTATE)
                {
                    handler = new ReqUploadViewStateHandler();
                }
                else if(command == COMMAND.CONNECT.SWITCHMAINSERVER)
                {
                    handler = new ReqSwitchMainServerHandler();
                }
                else if(command == COMMAND.CONNECT.RECONNECT)
                {
                    handler = new ReqReconnectHandler();
                }
            }
            if (handler != null)
            {
                return handler;
            }

            if (scenario == REQUEST_SCENARIO.CONNENT)
            {
                if (command == REQUEST_COMMAND.CONNECT.LOGIN)
                {
                    handler = new ReqLoginHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.LOGOUT)
                {
                    handler = new ReqLogoutHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.GETSOLUTIONLIST)
                {
                    handler = new ReqGetSolutionListHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.GETDOMAINLIST)
                {
                    handler = new ReqGetDomainListHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.ENTERDOMAIN)
                {
                    handler = new ReqEnterDomainHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.CREATEDOMAIN)
                {
                    //创建控制域
                    handler = new ReqCreateDomainHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.LEAVEDOMAIN)
                {
                    handler = new ReqLeaveDomainHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.SYNCVIEWSTATE)
                {
                    handler = new ReqSyncViewStateHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.RECONNECT)
                {
                    handler = new ReqReconnectHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.GETDOMAININSTANCEMODE)
                {
                    handler = new ReqGetDomainInstanceModeHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.UPDATECLIENTSTATUS)
                {
                    handler = new ReqUpdateClientStatusHandler();
                }
                else if (command == REQUEST_COMMAND.CONNECT.CHECKCLIENTSTATUS)
                {
                    handler = new ReqCheckClientStatusHandler();
                }
                else if (command == COMMAND.CONNECT.GETVIEWSTATE)
                {
                    handler = new ReqGetViewStateHandler();
                }
            }
            else if (scenario == REQUEST_SCENARIO.SCENE)
            {
                //场景
                if (command == REQUEST_COMMAND.SCENE.OPENSCENE)
                {
                    //打开场景
                    handler = new ReqOpenSceneHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.LOOPSCENE)
                {
                    //滚动场景
                    handler = new ReqLoopSceneHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.SWAPAREA)
                {
                    //交换场景
                    handler = new ReqSwapAreaHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.MOUSEEVENT)
                {
                    //鼠标事件
                    handler = new ReqMouseEventHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.CLOSESCENE)
                {
                    handler = new ReqCloseSceneHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.SETPROPERTYXMLSTRING)
                {
                    handler = new ReqSetPropertyXmlStringHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.MAGNIFYSCENE)
                {
                    handler = new ReqMagnifySceneHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.SHOWLASERPOINTER)
                {
                    handler = new ReqShowLaserPointerHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.PARTEVENT)
                {
                    handler = new ReqPartEventHandler();
                }
                else if (command == REQUEST_COMMAND.SCENE.SCRIPTNETEVENT)
                {
                    handler = new ReqScriptNetEventHandler();
                }
            }
            else if (scenario == REQUEST_SCENARIO.TABCONTAINER)
            {
                if (command == REQUEST_COMMAND.TABCONTAINER.CHANGE)
                {
                    handler = new ReqTabChangeHandler();
                }
            }
            else if (scenario == REQUEST_SCENARIO.SETTING)
            {
                if (command == REQUEST_COMMAND.SETTING.CHANGECONTROLSTATE)
                {
                    handler = new ReqChangeControlStateEventHandler();
                }
                else if (command == REQUEST_COMMAND.SETTING.RESETSCENE)
                {
                    handler = new ReqResetSceneHandler();
                }
                else if (command == REQUEST_COMMAND.SETTING.RESETSOLUTION)
                {
                    handler = new ReqResetSolutionHandler();
                }
            }
            else if (scenario == REQUEST_SCENARIO.SOLUTION)
            {
                if (command == REQUEST_COMMAND.SOLUTION.SWITCH)
                {
                    handler = new ReqSwitchSolutionHandler();
                }
                else if (command == REQUEST_COMMAND.SOLUTION.LOADINGFINISHED)
                {
                    handler = new ReqLoadingFinishedHandler();
                }
            }

            return handler;
        }
    }
}
